package com.qf.ex;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author sunyamei
 * @version V1.0
 * @Project springmvc_Demo
 * @Package com.qf.ex
 * @Description:
 * @Date 2022/7/14 14:15
 *
 */
@Component
public class MyHandleException implements HandlerExceptionResolver {


/**
 *
 * @param httpServletRequest  请求对象
 * @param httpServletResponse  响应对象
 * @param o   处理器（后端处理器 Controller）
 * @param e   异常对象
 * @return    方法的返回值 ModelAndView  替换我success.jsp
 */
@Override
public ModelAndView resolveException(HttpServletRequest httpServletRequest , HttpServletResponse httpServletResponse, Object o, Exception e) {
    e.printStackTrace();
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.addObject("msg", "系统异常,请联系管理员");
    //指定视图界面
    modelAndView.setViewName("/error.jsp");

    return modelAndView;
}

}
